package com.seek.service.imp;

import com.seek.core.BaseServiceImpl;
import com.seek.dao.BlacklistDao;
import com.seek.model.entity.TBlacklist;
import com.seek.service.BlacklistService;
import com.seek.util.CommonUtil;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * Created by weh on 2017/7/19.
 */
@Repository("blacklistService")
public class BlacklistServiceImpl extends BaseServiceImpl<TBlacklist> implements BlacklistService {

  @Autowired
  public void setDao(BlacklistDao blacklistDao) {
    super.setDao(blacklistDao);
  }

  public BlacklistDao getDao() {
    return (BlacklistDao) super.getDao();
  }
  @Override
  public boolean existPhone(String phoneNo) {

    List<Map<String,Object>> exits = this.getDao()
        .findMapBySql("select count(1) as cnt from t_blacklist where phone_no = ? and deleted = ?",
            new Object[]{phoneNo, 0});
    if(CollectionUtils.isNotEmpty(exits)){

      return CommonUtil.getLongValue(exits.get(0).get("cnt")) >0;
    }
    return true;
  }

  @Override
  public void saveBatch(List<TBlacklist> datas) throws Exception {
    if (CollectionUtils.isEmpty(datas)) {
      return;
    }
    for (TBlacklist data : datas) {
      this.getDao().insert(data);
    }
  }
}
